package com.ruoyi.system.domain.util;


import com.ruoyi.common.utils.LocalUrlConfig;
import com.ruoyi.system.domain.greatWall.GwReplacement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReplacementUtil {

    @Autowired
    private LocalUrlConfig localUrlConfig;

    public  List<String> getTimePeriods(List<String> slideshow, List<GwReplacement>replacement){

        List<String> timePeriods=new ArrayList<>();

        for (GwReplacement gwReplacement : replacement) {
            String url = gwReplacement.getUrl().replace(localUrlConfig.getLocalUrl(),"");
            timePeriods.add(url);
        }

        //置换图片和轮播图片数量一致,则判断图片是否一致
        if (slideshow.size() == timePeriods.size()){
            //循环slideshow,和timePeriods参数作比对,是否在timePeriods存在,若不存在,添加到timePeriods中
            for (int i = 0; i < slideshow.size(); i++) {
                String s = slideshow.get(i);
                boolean contains = timePeriods.contains(s);

                //不包含,添加
                if (!contains){
                    timePeriods.add(s);
                }
            }

            //循环timePeriods,和slideshow中的参数做对比,是否在slideshow中存在,不存在,直接删除
            for (int i = 0; i < timePeriods.size(); i++) {

                String s = timePeriods.get(i);

                boolean contains = slideshow.contains(s);
                if (!contains){
                    timePeriods.remove(s);
                    i--;
                }

            }
        }

        //置换图片和轮播图片数量不一致,则以slideshow数据为准
        if (slideshow.size() != timePeriods.size()){

            //循环查询timePeriods中是否包含slideshow中不同的参数,包含则删掉
            for (int i = 0; i < timePeriods.size(); i++) {
                String s = timePeriods.get(i);
                boolean contains = slideshow.contains(s);
                if (!contains){
                    timePeriods.remove(s);
                    i--;
                }
            }

            //循环查询slideshow参数,timePeriods中是否包含,不包含则添加
            for (int i = 0; i < slideshow.size(); i++) {
                String s = slideshow.get(i);
                boolean contains = timePeriods.contains(s);
                if (!contains){
                    timePeriods.add(s);
                }
            }
        }


        return timePeriods;


    }



}
